home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
54655
/
54655.xpi
/
chrome
/
gathererPopup.jar
/
content
/
overlay.js
< prev
next >
Wrap
Text File
|
2009-12-15
|
5KB
|
130 lines
with (gathererPopup) {
gathererPopup.overlay = {
///////////////////////////////////////////////////////////////////
// Initialization
///////////////////////////////////////////////////////////////////
onLoad: function(e) {
var self = gathererPopup.overlay;
window.addEventListener("mouseover", self.onMouseOver, false);
},
onUnload: function(e) {
var self = gathererPopup.overlay;
window.removeEventListener("load", self.onLoad, false);
window.removeEventListener("unload", self.onUnload, false);
window.removeEventListener("mouseover", self.onMouseOver, false);
},
///////////////////////////////////////////////////////////////////
// Events
///////////////////////////////////////////////////////////////////
onMouseOver: function(e) {
try {
var self = gathererPopup.overlay;
if (e.target.ownerDocument instanceof HTMLDocument) {
self.hidePopup(e.target.ownerDocument);
if (e.target.localName.toLowerCase() == "a")
self.hoverLink(e.target, e);
}
} catch (e) {
// if fails, ignore it
Cu.reportError(e);
}
},
///////////////////////////////////////////////////////////////////
// Logic
///////////////////////////////////////////////////////////////////
oldUrl: /javascript:autoCardWindow2?\(['"](.*?)['"]/i,
newUrl: "http://gatherer.wizards.com/Pages/Card/Details.aspx?name=",
req: null,
imgRelativeUrl: /\/Image.ashx\?multiverseid=(\d+)/i,
imgAbsoluteUrl: "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=###&type=card",
popupId: "firefox-gathererPopup",
cachePrefix: "firefox-gathererPopup-cache-",
hoverLink: function(a, e) {
if (a.href.search(this.oldUrl) >= 0) {
// if link matches, replace it with real url for middleclicking
var name = a.href.match(this.oldUrl)[1]
.replace(/_/g, " ")
.replace(/\[/g, "'");
var url = this.newUrl + encodeURIComponent(name);
a.setAttribute("href", url);
}
if (a.href.indexOf(this.newUrl) >= 0) {
// abort the previous request if user move mouse too fast
try {
this.req.abort();
this.req = null;
} catch (e) {
// ignore errors
}
// show popup and "Loading..." at mouse position
var popup = this.getPopup(a.ownerDocument);
popup.style.top = (e.pageY+10) + "px";
popup.style.left = (e.pageX+15) + "px";
// get gatherer page and extract the image link
if (a.hasAttribute("multiverseurl")) {
popup.style.background = "black url(" + a.getAttribute("multiverseurl")
+ ") no-repeat -12px -12px";
}
else {
this.req = get(a.href, (function(data) {
try {
if (!data) return;
var id = data.match(this.imgRelativeUrl)[1];
var url = this.imgAbsoluteUrl.replace("###", id);
popup.style.background = "black url(" + url + ") no-repeat -12px -12px";
a.setAttribute("multiverseurl", url);
} catch (e) {
// ignore errors
}
}).bind(this));
}
}
},
getPopup: function getPopup(doc) {
// always get rid of the previous popup
// this cost us next to nothing, ensure stray styles won't persist
this.hidePopup(doc);
// any styles we forget?
var popup = doc.createElement("div");
popup.setAttribute("id", this.popupId);
popup.setAttribute("style", "display: block; position: absolute; padding: 0; margin: 0;\
width: 198px; height: 283px; border: 1px solid #444;\
background: #555;\
-moz-box-shadow: black 2px 2px 10px;\
z-index: 999999;");
doc.body.appendChild(popup);
return popup;
},
hidePopup: function(doc) {
var popup = doc.getElementById(this.popupId);
if (popup) popup.parentNode.removeChild(popup);
},
}
window.addEventListener("load", gathererPopup.overlay.onLoad, false);
window.addEventListener("unload", gathererPopup.overlay.onUnload, false);
} // with